package cn.com.controller.wxController;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import cn.com.Enum.OrderStatus;
import cn.com.Enum.SessionAttr;
import cn.com.constant.Code;
import cn.com.db.model.Address;
import cn.com.db.model.DiyOrder;
import cn.com.db.model.DiyWork;
import cn.com.db.model.KeyWordSearch;
import cn.com.db.model.Order;
import cn.com.db.model.OrderItem;
import cn.com.db.model.Store;
import cn.com.db.model.Taste;
import cn.com.db.model.User;
import cn.com.db.model.WxDiyPayResult;
import cn.com.db.model.WxDiyRefundResult;
import cn.com.db.model.WxPayResult;
import cn.com.db.model.WxRefundResult;
import cn.com.db.service.AddressService;
import cn.com.db.service.CartService;
import cn.com.db.service.DiyOrderService;
import cn.com.db.service.DiyWorkService;
import cn.com.db.service.GoodsService;
import cn.com.db.service.KeyWordSearchService;
import cn.com.db.service.OrderService;
import cn.com.db.service.SellerService;
import cn.com.db.service.StoreService;
import cn.com.db.service.TasteService;
import cn.com.db.service.UserService;
import cn.com.db.service.WxDiyPayResultService;
import cn.com.db.service.WxDiyRefundResultService;
import cn.com.db.service.WxPayResultService;
import cn.com.db.service.WxRefundResultService;
import cn.com.util.DataResult;
import cn.com.util.JsonUtil;
import cn.com.util.SessionUtil;
import cn.com.util.TimeUtil;
import cn.com.util.UidUtil;
import cn.com.wxUtil.SendTemplateMessageUtil;
import cn.com.wxUtil.XMLUtil;
import cn.com.wxUtil.wxConstant;
import cn.com.wxUtil.refundUtil.WeiXinAtcion;
import cn.com.wxUtil.template.TemplateData;
import cn.com.wxUtil.template.WechatTemplate;

@RestController
@RequestMapping("/test1/")
public class TestController {
	@Autowired
	WxPayResultService wxPayResultService;
	@Autowired
	OrderService orderService;
	@Autowired
	StoreService storeService;
	@Autowired
	DiyOrderService diyOrderService;
	@Autowired
	UserService userService;
	@Autowired
	WxDiyPayResultService wxDiyPayResultService;
	@Autowired
	WxRefundResultService wxRefundResultService;
	@Autowired
	WxDiyRefundResultService wxDiyRefundResultService;
	@Autowired
	CartService cartService;
	@Autowired
	DiyWorkService diyWorkService;
	@Autowired
	KeyWordSearchService keyWordSearchService;
	@Autowired
	TasteService tasteService;
	@Autowired
	AddressService addressService;
	@Autowired
	GoodsService goodsService;
	@Autowired
	SellerService sellerService;

	@RequestMapping(value = "getTurnover", method = RequestMethod.GET)
	public String getTurnover() {
		DataResult dataResult = new DataResult();
		BigDecimal result = new BigDecimal("0.00");
		BigDecimal result1 = orderService.getTurnover(null, null);
		if(result1 != null){
			result = result.add(result1);
		}
		BigDecimal result2 = diyOrderService.getTurnover(null, null);
		if(result2 != null){
			result = result.add(result2);
		}
		dataResult.setData(result);
		dataResult.setCode(Code.SUCCESS);
		dataResult.setMessage("返回成功");
		return JsonUtil.toJsonString(dataResult);
	}

	@RequestMapping(value = "getTodayTurnover", method = RequestMethod.GET)
	public String getTodayTurnover() {
		DataResult dataResult = new DataResult();
		BigDecimal result = new BigDecimal("0.00");
		BigDecimal result1 = orderService.getTodayTurnover(null, null);
		if(result1 != null){
			result = result.add(result1);
		}
		BigDecimal result2 = diyOrderService.getTodayTurnover(null, null);
		if(result2 != null){
			result = result.add(result2);
		}
		dataResult.setData(result);
		dataResult.setCode(Code.SUCCESS);
		dataResult.setMessage("返回成功");
		return JsonUtil.toJsonString(dataResult);
	}

	@RequestMapping(value = "getDealPeopleNum", method = RequestMethod.GET)
	public String getDealPeopleNum() {
		DataResult dataResult = new DataResult();
		dataResult.setData(orderService.getDealPeopleNum(null, null) + diyOrderService.getDealPeopleNum(null, null));
		dataResult.setCode(Code.SUCCESS);
		dataResult.setMessage("返回成功");
		return JsonUtil.toJsonString(dataResult);
	}

	@RequestMapping(value = "getOrderNum", method = RequestMethod.GET)
	public String getOrderNum() {
		DataResult dataResult = new DataResult();
		dataResult.setData(orderService.getOrderNum(null, null) + diyOrderService.getDiyOrderNum(null, null));
		dataResult.setCode(Code.SUCCESS);
		dataResult.setMessage("返回成功");
		return JsonUtil.toJsonString(dataResult);
	}

	@RequestMapping(value = "getSellerNum", method = RequestMethod.GET)
	public String getSellerNum() {
		DataResult dataResult = new DataResult();
		dataResult.setData(sellerService.getSellerNum());
		dataResult.setCode(Code.SUCCESS);
		dataResult.setMessage("返回成功");
		return JsonUtil.toJsonString(dataResult);
	}

	@RequestMapping(value = "getBuyerNum", method = RequestMethod.GET)
	public String getBuyerNum() {
		DataResult dataResult = new DataResult();
		dataResult.setData(userService.getUserNum());
		dataResult.setCode(Code.SUCCESS);
		dataResult.setMessage("返回成功");
		return JsonUtil.toJsonString(dataResult);
	}

	@RequestMapping(value = "getStoreNum", method = RequestMethod.GET)
	public String getStoreNum() {
		DataResult dataResult = new DataResult();
		dataResult.setData(storeService.countStore(new Store()));
		dataResult.setCode(Code.SUCCESS);
		dataResult.setMessage("返回成功");
		return JsonUtil.toJsonString(dataResult);
	}

	@RequestMapping(value = "getGoodsNum", method = RequestMethod.GET)
	public String getGoodsNum() {
		DataResult dataResult = new DataResult();
		dataResult.setData(goodsService.getGoodsNum());
		dataResult.setCode(Code.SUCCESS);
		dataResult.setMessage("返回成功");
		return JsonUtil.toJsonString(dataResult);
	}

	
}
